package cn.edu.jiangnan.cashmanagement.web.user;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cn.edu.jiangnan.cashmanagement.common.bean.BaseBean;
import cn.edu.jiangnan.cashmanagement.entity.RoleEntity;
import cn.edu.jiangnan.cashmanagement.service.user.IRoleService;

@Component
@Scope(value="session")
public class RoleBean extends BaseBean{

	private static final long serialVersionUID = 1L;
	
	@Autowired
	IRoleService 				roleSerivce;
	
	private RoleEntity 			role;
	
	private List<RoleEntity> 	roleList;
	
	private Map<String,String>  roleAuthorityMp;
	
	public Map<String, String> getRoleAuthorityMp() {
		return roleAuthorityMp;
	}

	public void setRoleAuthorityMp(Map<String, String> roleAuthorityMp) {
		this.roleAuthorityMp = roleAuthorityMp;
	}

	public RoleEntity getRole() {
		return role;
	}

	public void setRole(RoleEntity role) {
		this.role = role;
	}
	
	@PostConstruct
	public void init(){
		roleAuthorityMp = new LinkedHashMap<String, String>(4);
		roleAuthorityMp.put(RoleEntity.ROLE_URSER,RoleEntity.ROLE_URSER);
		roleAuthorityMp.put(RoleEntity.ROLE_ACCOUNTER,RoleEntity.ROLE_ACCOUNTER);
		roleAuthorityMp.put(RoleEntity.ROLE_MANAGER,RoleEntity.ROLE_MANAGER);
		roleAuthorityMp.put(RoleEntity.ROLE_ADMIN,RoleEntity.ROLE_ADMIN);
		getRoleList();
	}

	public String addRole(){
//		http://stackoverflow.com/questions/5951603/how-to-confirm-jsf-button-click-by-jquery-dialog-using-the-button-from-datatable	
		return null;
	}
	
	public List<RoleEntity> getRoleList(){
		roleList = new ArrayList<RoleEntity>(5);
		for(int i=0;i<5;i++){
			RoleEntity role = new RoleEntity();
			role.setRoleId(Long.valueOf(i));
			role.setRoleName("TEST"+i);
			role.setRole("tttt");
			roleList.add(role);
		}
		return roleList;
	} 
	
	
}
